// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------

import request from '@/utils/request'

export function systemConfigCheck(pram) {
  const data = {
    name: pram.name
  }
  return request({
    url: '/admin/system/config/check',
    method: 'GET',
    params: data
  })
}

export function systemConfigInfo(pram) {
  const data = {
    formId: pram.id
  }
  return request({
    url: '/admin/system/config/info',
    method: 'GET',
    params: data
  })
}

export function systemConfigSave(pram) {
  return request({
    url: '/admin/system/config/save/form',
    method: 'POST',
    data: pram
  })
}

/**
 * 文件上传
 * @param data
 */
export function fileFileApi(data, params) {
  return request({
    url: '/admin/upload/file',
    method: 'POST',
    params,
    data,
    timeout: 300000 // 5分钟超时，适合小文件上传到腾讯云COS
  })
}

/**
 * 图片上传
 * @param data
 */
export function fileImageApi(data, params) {
  return request({
    url: '/admin/upload/image',
    method: 'POST',
    params,
    data
  })
}

/**
 * 图片列表
 * @param data
 */
export function fileListApi(params) {
  return request({
    url: '/admin/system/attachment/list',
    method: 'get',
    params
  })
}

/**
 * 图片列表 删除图片
 * @param data
 */
export function fileDeleteApi(id) {
  return request({
    url: `/admin/system/attachment/delete/${id}`,
    method: 'get'
  })
}

/**
 * 图片列表 移動分類
 * @param data
 */
export function attachmentMoveApi(data) {
  return request({
    url: `/admin/system/attachment/move`,
    method: 'post',
    data
  })
}

/**
 * 微信上传图片
 * @param data
 */
export function wechatUploadApi(data, params) {
  return request({
    url: `/admin/wechat/media/upload`,
    method: 'post',
    data,
    params
  })
}

/**
 * 检查大文件是否已存在
 * @param identifier 文件唯一标识符
 */
export function checkBigFileExistsApi(identifier) {
  return request({
    url: '/admin/bigfile/check',
    method: 'GET',
    params: { identifier }
  })
}

/**
 * 上传大文件分片
 * @param data FormData包含分片文件和参数
 */
export function uploadBigFileChunkApi(data) {
  return request({
    url: '/admin/bigfile/chunk',
    method: 'POST',
    data,
    timeout: 300000 // 5分钟超时，适合大分片上传
  })
}

/**
 * 合并大文件分片
 * @param params 合并参数
 */
export function mergeBigFileChunksApi(params) {
  return request({
    url: '/admin/bigfile/merge',
    method: 'POST',
    params,
    timeout: 600000 // 10分钟超时，适合大文件合并
  })
}

/**
 * 获取大文件上传进度
 * @param identifier 文件唯一标识符
 */
export function getBigFileUploadProgressApi(identifier) {
  return request({
    url: '/admin/bigfile/progress',
    method: 'GET',
    params: { identifier }
  })
}

/**
 * 取消大文件上传
 * @param identifier 文件唯一标识符
 */
export function cancelBigFileUploadApi(identifier) {
  return request({
    url: '/admin/bigfile/cancel',
    method: 'DELETE',
    params: { identifier }
  })
}

